package com.bicycle.rentalsystem.dao.impl.admin;

import com.bicycle.rentalsystem.dao.admin.StationDao;
import com.bicycle.rentalsystem.pojo.admin.Station;

import java.util.List;

/**
 * @author Third uncle
 * @date 2022/11/27 - 16:40
 */
public class StationDaoImpl extends BaseDao implements StationDao {
    @Override
    public List<Station> queryStations() {
        String sql="SELECT sid,station_name stationName \n" +
                "FROM station ";
        List<Station> list = queryForList(Station.class, sql);
        return list;
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql="SELECT COUNT(*) FROM station";
        Object o = queryForSingleValue(sql);
        String s = o.toString();
        Integer a= Integer.valueOf(s);
        return a;
    }

    @Override
    public List<Station> queryForPageItems(Integer begin, Integer pageSize) {
        String sql="SELECT sid,station_name stationName FROM station\n" +
                "LIMIT ?,?";
        List<Station> list = queryForList(Station.class, sql, begin, pageSize);
        return list;
    }

    @Override
    public void addStation(Station station) {
        String sql="INSERT INTO station(`station_name`) VALUES(?)";
        update(sql,station.getStationName());
    }

    @Override
    public void deleteStationById(int aId) {
        String sql="DELETE FROM station WHERE sid=?";
        update(sql,aId);
    }

    @Override
    public List<Station> getStation() {
        String sql="SELECT sid,station_name stationName FROM station";
        List<Station> list = queryForList(Station.class, sql);
        return list;
    }
}
